class Solution {
    public int countBattleships(char[][] board) {
        int m=board.length;
        int n=board[0].length;
        int ans=0;
        for(int i = 0;i < m;i++) {
            for(int j = 0;j < n;j++) {
                if(board[i][j]=='X'){
                    board[i][j]='.';
                    for(int q=j+1;q<n&&board[i][q]=='X';q++)
                    {
                        board[i][q]='.';
                    }
                    for(int w = i+1;w < m&&board[w][j]=='X';w++) {
                        board[w][j]='.';
                    }
                    ans++;
                }
            }
        }
        return ans;
    }
}
